package com.exam.scjp5.objectives.section_6;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ExampleCollectionsSort
{
    public static void main(String args[])
    {
        List<DVD> list = new ArrayList<DVD>();
        list.add(new DVD());
        list.add(new DVD());
        list.add(new DVD());
        
        Collections.sort(list); // ERROR! because DVD does not implements Comparable interface.
        
        // with DVD2
        List<DVD2> list2 = new ArrayList<DVD2>();
        list2.add(new DVD2());
        list2.add(new DVD2());
        list2.add(new DVD2());
        
        Collections.sort(list2);
    }
}

class DVD
{
    String title; 
}

// This should be implemented with Comparable<DVD2> not to be too risky.
class DVD2 implements Comparable
{
    String title;
    @Override
    public int compareTo(Object o)
    {
        // TODO Auto-generated method stub
        String target = (String) o;
        return this.title.compareTo(target);
    }
}

class Sorter implements Comparator<String>
{
    @Override
    public int compare(String o1, String o2)
    {
        // TODO Auto-generated method stub
        return o1.compareTo(o2);
    }
}